package com.practice.draw.customview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View

/**
 * Created by lgs on 2018/7/17.
 */
class DrawCircleView @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private val DENSITY = resources.displayMetrics.density
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)

    override fun onDraw(canvas: Canvas?) {
        canvas?.save()
        paint.style = Paint.Style.FILL
        canvas?.drawCircle(width / 2f - DENSITY * 60, DENSITY * 55, 150f, paint)

        paint.strokeWidth = DENSITY
        paint.style = Paint.Style.STROKE
        canvas?.drawCircle(width / 2f + DENSITY * 60, DENSITY * 55, 150F, paint)

        paint.style = Paint.Style.FILL
        paint.color = Color.BLUE
        canvas?.drawCircle(width / 2f - DENSITY * 60, height / 2f - DENSITY * 80, 150F, paint)

        paint.style = Paint.Style.STROKE
        paint.strokeWidth = DENSITY * 15
        paint.color = Color.BLACK
        canvas?.drawCircle(width / 2f + DENSITY * 60, height / 2f - DENSITY * 80, 150F, paint)
        canvas?.restore()

        canvas?.save()
        paint.strokeWidth = DENSITY
        paint.textSize = 18 * DENSITY
        paint.textAlign = Paint.Align.CENTER
        canvas?.drawText("圆绘制作业", width / 2f, height / 2 + DENSITY * 50, paint)
    }

}